//
//  NewsPindaoView.m
//  News
//
//  Created by 李旭阳 on 15/12/28.
//  Copyright © 2015年 apple. All rights reserved.
//
#define yWIDTH [UIScreen mainScreen].bounds.size.width
#define yPindaoIdentifier @"NewsPindaoCell"
#import "NewsPindaoView.h"
#import "NewsPindaoCell.h"
#import "NewsPindao.h"

@interface NewsPindaoView()<UICollectionViewDataSource>
@property(nonatomic,strong)NSMutableArray *pindaos;

@end

@implementation NewsPindaoView

- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(nonnull UICollectionViewLayout *)layout
{
    self = [super initWithFrame:frame collectionViewLayout:layout];
    // 调试
    self.backgroundColor = [UIColor redColor];

    self.showsHorizontalScrollIndicator = NO;
    //注册cell
    [self registerClass:[NewsPindaoCell class] forCellWithReuseIdentifier:yPindaoIdentifier];

    self.dataSource = self;
    
    return self;
}

#pragma mark 设置frame
-(void)layoutSubviews{
    [super layoutSubviews];
    self.frame = CGRectMake(0, 20, yWIDTH, 35);

}

#pragma mark 数据方法
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.pindaos.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    NewsPindaoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:yPindaoIdentifier forIndexPath:indexPath];
    
    NewsPindao *pindao = self.pindaos[indexPath.item];
    NSLog(@"%@--%@",pindao.tname,pindao.tid);
    
    return cell;
}

#pragma mark 懒加载
-(NSMutableArray *)pindaos{
    if (!_pindaos) {
        _pindaos = [NSMutableArray array];
    }
    return _pindaos;
}

@end
